package com.ssy.lingxi.contract.controller;

import com.ssy.lingxi.common.constant.member.RoleTypeEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.contract.model.vo.applyamount.request.ApplyAmountOrderDetailPageVO;
import com.ssy.lingxi.contract.model.vo.applyamount.request.ApplyAmountOrderDetailVO;
import com.ssy.lingxi.contract.model.vo.applyamount.request.ApplyAmountOrderSummaryPageVO;
import com.ssy.lingxi.contract.model.vo.applyamount.response.ApplyAmountOrderDetailQueryVO;
import com.ssy.lingxi.contract.model.vo.applyamount.response.ApplyAmountOrderInfoVO;
import com.ssy.lingxi.contract.model.vo.applyamount.response.ApplyAmountOrderSummaryQueryVO;
import com.ssy.lingxi.contract.model.vo.common.response.PageItemVO;
import com.ssy.lingxi.contract.model.vo.common.response.StatusVO;
import com.ssy.lingxi.contract.model.vo.execute.request.ContractExecuteInfoPageVO;
import com.ssy.lingxi.contract.model.vo.execute.request.ContractExecutePartyAPageVO;
import com.ssy.lingxi.contract.model.vo.execute.request.ContractExecutePartyBPageVO;
import com.ssy.lingxi.contract.model.vo.execute.request.ContractExecutePayDetailVO;
import com.ssy.lingxi.contract.model.vo.execute.response.ContractExecuteDetailVO;
import com.ssy.lingxi.contract.model.vo.execute.response.ContractExecuteInfoQueryVO;
import com.ssy.lingxi.contract.model.vo.execute.response.ContractExecuteQueryVO;
import com.ssy.lingxi.contract.service.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 合同能力-合同执行
 * @author 伍将
 * @date 2021/02/02
 * @version 2.0.0
 */
@RestController
@RequestMapping("/contract/execute")
public class ContractExecuteController extends BaseController {

    @Resource
    private IContractExecuteService contractExecuteService;

    @Resource
    private IContractExecuteInfoService contractExecuteInfoService;

    @Resource
    private IApplyAmountOrderService applyAmountOrderService;

    @Resource
    private IApplyAmountOrderDetailService applyAmountOrderDetailService;
    @Resource
    private IStatusService statusService;

    /**
     * 甲方分页查询合同列表
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageListByPartyA", method = RequestMethod.GET)
    public Wrapper<PageData<ContractExecuteQueryVO>> pageListByPartyA(HttpServletRequest httpRequest, @Valid ContractExecutePartyAPageVO pageVO) {
        return contractExecuteService.pageListByPartyA(getSysUser(httpRequest), pageVO);
    }

    /**
     * 乙方分页查询合同列表
     * @author 伍将
     * @date 2021/2/2
     **/
    @RequestMapping(value = "/pageListByPartyB", method = RequestMethod.GET)
    public Wrapper<PageData<ContractExecuteQueryVO>> pageListByPartyB(HttpServletRequest httpRequest, @Valid ContractExecutePartyBPageVO pageVO) {
        return contractExecuteService.pageListByPartyB(getSysUser(httpRequest), pageVO);
    }

    /**
     * 查询外部状态列表
     * @author 伍将
     * @date 2021/2/2
     **/
    @Deprecated
    @RequestMapping(value = "/getOuterStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getOuterStatusList() {
        return contractExecuteService.getOuterStatusList();
    }

    /**
     * 获取合同详情
     * @author 伍将
     * @date 2021/3/9
     **/
    @RequestMapping(value = "/getDetail", method = RequestMethod.GET)
    public Wrapper<ContractExecuteDetailVO> getDetail(HttpServletRequest httpRequest, Long contractId) {
        return contractExecuteService.getDetail(getSysUser(httpRequest), contractId);
    }

    /**
     * 分页查询合同执行情况
     * @author 伍将
     * @date 2021/3/9
     **/
    @RequestMapping(value = "/pageExecuteInfoList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractExecuteInfoQueryVO>> pageExecuteInfoList(HttpServletRequest httpRequest,@Valid ContractExecuteInfoPageVO pageVO) {
        return contractExecuteInfoService.pageList(getSysUser(httpRequest),pageVO);
    }

    /**
     * 合同执行-合同执行详情-付款明细列表
     * @author ds
     * @date 2021/4/7
     **/
    @RequestMapping(value = "/executeInfo/payDetailList", method = RequestMethod.GET)
    public Wrapper<List<com.ssy.lingxi.contract.model.vo.applyamount.response.ApplyAmountOrderDetailVO>> payDetailList(HttpServletRequest httpRequest, @Valid ContractExecutePayDetailVO detailVO) {
        return applyAmountOrderDetailService.payDetailList(getSysUser(httpRequest),detailVO);
    }

    /**
     * 合同协通-合同执行详情-合同付款详情
     * @author ds
     * @date 2021/4/7
     **/
    @RequestMapping(value = "/executeInfo/payDetailInfo", method = RequestMethod.GET)
    public Wrapper<ApplyAmountOrderInfoVO> payDetailInfo(@Valid ApplyAmountOrderDetailVO detailVO) {
        return  applyAmountOrderService.payDetailInfo(detailVO);
    }

    /**
     * 合同协通-合同执行详情-合同付款详情-付款明细
     * @author ds
     * @date 2021/4/7
     **/
    @RequestMapping(value = "/executeInfo/payDetailInfo/pagePayDetail", method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountOrderDetailQueryVO>> pagePayDetail(@Valid ApplyAmountOrderDetailPageVO pageVO) {
        return applyAmountOrderDetailService.pageList(pageVO);
    }

    /**
     * 分页查询合同请款汇总-甲方
     * @author ds
     * @date 2021/4/7
     **/
    @RequestMapping(value = "/pageListForSummaryByPartyA", method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountOrderSummaryQueryVO>> pageListForSummaryByPartyA(HttpServletRequest httpRequest, @Valid ApplyAmountOrderSummaryPageVO pageVO) {
        return applyAmountOrderService.pageListForSummary(getSysUser(httpRequest), pageVO);
    }

    /**
     * 分页查询合同请款汇总-乙方
     * @author ds
     * @date 2021/4/7
     **/
    @RequestMapping(value = "/pageListForSummaryByPartyB", method = RequestMethod.GET)
    public Wrapper<PageData<ApplyAmountOrderSummaryQueryVO>> pageListForSummaryByPartyB(HttpServletRequest httpRequest, @Valid ApplyAmountOrderSummaryPageVO pageVO) {
        pageVO.setRoleType(RoleTypeEnum.SERVICE_PROVIDER.getCode());
        return applyAmountOrderService.pageListForSummary(getSysUser(httpRequest), pageVO);
    }

    /**
     * 状态查询
     * @author ds
     * @date 2021/5/28
     **/
    @RequestMapping(value = "/status/list", method = RequestMethod.GET)
    public Wrapper<StatusVO> statusList(HttpServletRequest httpRequest) {
        return statusService.getStatusByContractExecute();
    }
}
